package com.ysd.admin.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.ysd.dao.impl.XiYangYangChaoShiDaoimpl;
import com.ysd.entity.XiYangYangChaoShi;
import com.ysd.util.BaseServlet;
import com.ysd.util.Result;


public class AdminXiYangYangChaoShiServlet extends BaseServlet {
	/**
	 * localhost:8080/xiyangyangchaoshi/AdminXiYangYangChao?reqName=selXiYangYangChaoShi
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void selXiYangYangChaoShi(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		PrintWriter out=response.getWriter();
		
		XiYangYangChaoShiDaoimpl xyy=new XiYangYangChaoShiDaoimpl();
		XiYangYangChaoShi  xyycs=xyy.getXiYangYangCahoShi();
		
		Gson gson=new Gson();
		
		
		out.print(gson.toJson(xyycs));
		
		out.flush();
		out.close();
	}
	
	
	/**
	 * localhost:8080/xiyangyangchaoshi/AdminXiYangYangChao?reqName=getXiYangYangChaoShiById
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void getXiYangYangChaoShiById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		PrintWriter out=response.getWriter();
		int id=Integer.parseInt(request.getParameter("id"));
		XiYangYangChaoShiDaoimpl xyy=new XiYangYangChaoShiDaoimpl();
		XiYangYangChaoShi  xyycs=xyy.getXiYangYangChaoShiById(id);
		
		Gson gson=new Gson();
		
		
		out.print(gson.toJson(xyycs));
		
		out.flush();
		out.close();
	}
	
	
	
	/**
	 * localhost:8080/xiyangyangchaoshi/AdminXiYangYangChao?reqName=editXiYangYangChaoShiById
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void editXiYangYangChaoShiById(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		PrintWriter out=response.getWriter();
		
		int id=Integer.parseInt(request.getParameter("id"));
		String chaoShiName=request.getParameter("chaoShiName");
		String chaoShiJieShao=request.getParameter("chaoShiJieShao");
		String logo=request.getParameter("logo");
		String chaoShiDianHua=request.getParameter("chaoShiDianHua");
		String chaoShiYouXiang=request.getParameter("chaoShiYouXiang");
		String chaoShiWangZhi=request.getParameter("chaoShiWangZhi");
		String chaoShiDiZhi=request.getParameter("chaoShiDiZhi");
		String qiYeWenHua=request.getParameter("qiYeWenHua");
		String chaoShiXiangJie=request.getParameter("chaoShiXiangJie");
		String chaoShiErWeiMa=request.getParameter("chaoShiErWeiMa");
		
		XiYangYangChaoShi x=new XiYangYangChaoShi(chaoShiName, logo, chaoShiJieShao, chaoShiDianHua, chaoShiYouXiang, chaoShiWangZhi, chaoShiDiZhi, qiYeWenHua, chaoShiXiangJie, chaoShiErWeiMa, id);
		XiYangYangChaoShiDaoimpl xyy=new XiYangYangChaoShiDaoimpl();
		int  n=xyy.editXiYangYangChaoShiById(x);
		
		if(n>0) {
			out.print(Result.toClient(true, "修改成功", ""));
		}else {
			out.print(Result.toClient(true, "修改失败", "您的操作有误"));
		}
		
		out.flush();
		out.close();
	}
}
